home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-wtcoio < prev    next >
Text File  |  1996-02-12  |  6KB  |  172 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --   A D A . T E X T _ I O . W I D E _ T E X T _ IO . C O M P L E X _ I O   --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Complex_Aux;
  37. with System.WCh_Con; use System.WCh_Con;
  38. with System.WCh_WtS; use System.WCh_WtS;
  39.  
  40. with Ada.Unchecked_Conversion;
  41.  
  42. package body Ada.Text_IO.Wide_Text_IO.Complex_IO is
  43.  
  44.    package Aux renames Ada.Text_IO.Complex_Aux;
  45.    --  We can share the normal Text_IO circuits for the non-string cases
  46.    --  since numeric values involve no wide character values, and the first
  47.    --  character of a wide character value (ESC or an upper half character)
  48.    --  always looks non-numeric for the Get case). For the Wide_String cases
  49.    --  we can share the normal Text_IO circuits by converting to String.
  50.  
  51.    subtype LLF is Long_Long_Float;
  52.    --  Type used for calls to routines in Aux
  53.  
  54. --   subtype TFT is Ada.Text_IO.File_Type;
  55.    --  File type required for calls to routines in Aux
  56.  
  57.    function TFT is new
  58.      Ada.Unchecked_Conversion (File_Type, Ada.Text_IO.File_Type);
  59.    --  This unchecked conversion is to get around a visibility bug in
  60.    --  GNAT version 2.04w. It should be possible to simply use the
  61.    --  subtype declared above and do normal checked conversions.
  62.  
  63.    ---------
  64.    -- Get --
  65.    ---------
  66.  
  67.    procedure Get
  68.      (File  : in  File_Type;
  69.       Item  : out Complex;
  70.       Width : in  Field := 0)
  71.    is
  72.       Real_Item  : Real'Base;
  73.       Imag_Item  : Real'Base;
  74.  
  75.    begin
  76.       Aux.Get (TFT (File), LLF (Real_Item), LLF (Imag_Item), Width);
  77.       Item := (Real_Item, Imag_Item);
  78.  
  79.    exception
  80.       when Constraint_Error => raise Data_Error;
  81.    end Get;
  82.  
  83.    ---------
  84.    -- Get --
  85.    ---------
  86.  
  87.    procedure Get
  88.      (Item  : out Complex;
  89.       Width : in  Field := 0)
  90.    is
  91.    begin
  92.       Get (Current_Input, Item, Width);
  93.    end Get;
  94.  
  95.    ---------
  96.    -- Get --
  97.    ---------
  98.  
  99.    procedure Get
  100.      (From : in  Wide_String;
  101.       Item : out Complex;
  102.       Last : out Positive)
  103.    is
  104.       Real_Item : Real'Base;
  105.       Imag_Item : Real'Base;
  106.  
  107.       S : constant String := Wide_String_To_String (From, WCEM_Upper);
  108.       --  String on which we do the actual conversion. Note that the method
  109.       --  used for wide character encoding is irrelevant, since if there is
  110.       --  a character outside the Standard.Character range then the call to
  111.       --  Aux.Gets will raise Data_Error in any case.
  112.  
  113.    begin
  114.       Aux.Gets (S, LLF (Real_Item), LLF (Imag_Item), Last);
  115.       Item := (Real_Item, Imag_Item);
  116.  
  117.    exception
  118.       when Data_Error => raise Constraint_Error;
  119.    end Get;
  120.  
  121.    ---------
  122.    -- Put --
  123.    ---------
  124.  
  125.    procedure Put
  126.      (File : in File_Type;
  127.       Item : in Complex;
  128.       Fore : in Field := Default_Fore;
  129.       Aft  : in Field := Default_Aft;
  130.       Exp  : in Field := Default_Exp)
  131.    is
  132.    begin
  133.       Aux.Put (TFT (File), LLF (Re (Item)), LLF (Im (Item)), Fore, Aft, Exp);
  134.    end Put;
  135.  
  136.    ---------
  137.    -- Put --
  138.    ---------
  139.  
  140.    procedure Put
  141.      (Item : in Complex;
  142.       Fore : in Field := Default_Fore;
  143.       Aft  : in Field := Default_Aft;
  144.       Exp  : in Field := Default_Exp)
  145.    is
  146.    begin
  147.       Put (Current_Output, Item, Fore, Aft, Exp);
  148.    end Put;
  149.  
  150.    ---------
  151.    -- Put --
  152.    ---------
  153.  
  154.    procedure Put
  155.      (To   : out Wide_String;
  156.       Item : in  Complex;
  157.       Aft  : in  Field := Default_Aft;
  158.       Exp  : in  Field := Default_Exp)
  159.    is
  160.       S : String (To'First .. To'Last);
  161.  
  162.    begin
  163.       Aux.Puts (S, LLF (Re (Item)), LLF (Im (Item)), Aft, Exp);
  164.  
  165.       for J in S'Range loop
  166.          To (J) := Wide_Character'Val (Character'Pos (S (J)));
  167.       end loop;
  168.  
  169.    end Put;
  170.  
  171. end Ada.Text_IO.Wide_Text_IO.Complex_IO;
  172.